<template>
  <div id="app">
    <header class="app-header">
      <h1>Vue 子应用</h1>
      <p>当前路由: {{ $route.path }}</p>
    </header>
    
    <nav class="app-nav">
      <router-link to="/">首页</router-link>
      <router-link to="/page1">Page 1</router-link>
      <router-link to="/page2">Page 2</router-link>
    </nav>
    
    <div class="app-content">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
export default {
  name: 'App',
  mounted() {
    // 监听主应用传来的路由变化事件
    window.addEventListener('main-app-route-change', this.handleRouteChange);
  },
  beforeUnmount() {
    window.removeEventListener('main-app-route-change', this.handleRouteChange);
  },
  methods: {
    handleRouteChange(event) {
      console.log('[vue-app] received route change from main app:', event.detail);
    }
  }
}
</script>

<style scoped>
#app {
  text-align: center;
  padding: 20px;
  font-family: Avenir, Helvetica, Arial, sans-serif;
}

.app-header {
  background-color: #42b983;
  padding: 20px;
  color: white;
  border-radius: 8px;
  margin-bottom: 20px;
}

.app-nav {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.app-nav a {
  padding: 10px 20px;
  background-color: #42b983;
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-weight: bold;
  transition: background-color 0.3s;
}

.app-nav a:hover {
  background-color: #359c6d;
}

.app-content {
  min-height: 300px;
}

.app-content h2 {
  color: #42b983;
}

.app-content p {
  font-size: 18px;
  color: #333;
}

.router-link-active {
  background-color: #359c6d !important;
}
</style>